package com.ruoyi.web.controller.combat.socialmedia;

import com.ruoyi.combat.domain.userlocation.CombatUser;
import com.ruoyi.combat.service.socialmedia.CombatCrawlService;
import com.ruoyi.combat.service.userlocation.ICombatUserService;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/combat/crawl")
@Api(tags = "公共服务：用户信息采集程序")
public class CombatCrawlController {

    @Autowired
    private ICombatUserService combatUserService;
    @Autowired
    private CombatCrawlService combatCrawlService;

    @ApiOperation(value = "按照用户id采集用户信息及发布内容")
    @GetMapping("/weibo")
    public AjaxResult crawlWeiboByUserId(@ApiParam(name = "id", value = "需要采集的用户id", required = true)
                                             @RequestParam(required = true) String id) {
        combatCrawlService.crawlWeiboByUserId(id);
        AjaxResult ajaxResult = AjaxResult.success("采集成功");
        return ajaxResult;
    }

    @ApiOperation(value = "多个用户信息及发布内容采集")
    @GetMapping("/moreWeibo")
    public AjaxResult crawlWeiboByUserIds(@ApiParam(name = "ids", value = "需要采集的用户ids", required = true)
                                              @RequestParam(required = true) Long[] ids) {
        if (ids == null || ids.length == 0) {
            return AjaxResult.error("请传入需要采集的用户id");
        }
        combatCrawlService.crawlWeiboByUserIds(ids);
        AjaxResult ajaxResult = AjaxResult.success("采集成功");
        return ajaxResult;
    }
    @ApiOperation(value = "多个用户信息及发布内容采集")
    @GetMapping("/moreWeiboInfo")
    public AjaxResult moreWeiboInfo(@ApiParam(name = "ids", value = "需要采集的用户微博ids", required = true)
                                              @RequestParam(required = true) String[] ids) {
        if (ids == null || ids.length == 0) {
            return AjaxResult.error("请传入需要采集的用户id");
        }
        combatCrawlService.moreWeiboInfo(ids);
        AjaxResult ajaxResult = AjaxResult.success("采集成功");
        return ajaxResult;
    }

    @ApiOperation(value = "全部用户信息及发布内容采集")
    @GetMapping("/allWeibo")
    public AjaxResult crawlAllWeiboByUserIds() {
        combatCrawlService.crawlAllWeiboByUserIds();
        AjaxResult ajaxResult = AjaxResult.success("采集成功");
        return ajaxResult;
    }

    @ApiOperation(value = "按照用户id采集用户信息--系统应能够处理至少100个用户数据采集")
    @GetMapping("/crawlByUserId")
    public AjaxResult crawlByUserId(@RequestParam String id) {
//        combatCrawlService.crawlWeiboByUserId(id);
        AjaxResult ajaxResult = AjaxResult.success("采集成功");
        return ajaxResult;
    }
}
